<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2024/3/16
 * Time: 14:19
 */
namespace app\model\index;


use think\model\concern\SoftDelete;

class Order extends Base
{
    protected $append = [
        'order_type_text',
        'status_text',
        'address_list',
        'amount_daxie'
    ];
    use SoftDelete;

    public function userInfo(){
        return $this->hasOne(User::class,'id','user_id')->bind(['username']);
    }

    public function info(){
        return $this->hasMany(OrderInfo::class,'order_no','order_no');
    }

    public function getKeywordsListAttr($value,$data){

    }

    public function getTypeTextAttr($value,$data){
        $array = [
            1 => '全端',
            2 => 'PC端',
            3 => '手机端',
            4 => '套餐'
        ];
        return $array[$data['type']];
    }

    public function getAmountDaxieAttr($value,$data){
        return numberToChineseUppercase($data['amount']);
    }

    public function getKeywordAreaAttr($value){
        if ($value == 'baidu')
            return '百度';
        else if($value == 'douying')
            return '抖音';
        else if($value == 'google')
            return '谷歌';
        else
            return '全平台';
    }

    public function getAddressListAttr($value,$data)
    {
        $array = explode(',', $data['address']);
        if ($data['keyword_area'] != 'google' && $data['keyword_area'] != '谷歌') {
            $count = count($array);
            if ($count >= 30) {
                return ['全国'];
            } else {
                return $array;
            }
        }else{
            return $array;
        }
    }

    public function getOrderTypeTextAttr($value,$data){
        $array = [
            1 => '关键词投放'
        ];
        return $array[$data['order_type']];
    }

    public function getStatusTextAttr($value,$data){
        $array = [
            1 => '待确认',
            2 => '确认下单',
            3 => '已完成'
        ];
        return $array[$data['status']];
    }
}